<template>
    <div>
        <div class="search-check" v-for="(item, index) in data " :key=index>
            <template v-if="data.length>1">
                <div class="mb-ten">{{ item.title || ''}}</div>
                <div class="mb-ten">
                    <a-checkbox :indeterminate="item.indeterminate" :checked="item.checkAll"
                        @change="onCheckAllChange($event, index)" style="margin-right: 10px;">
                        全部
                    </a-checkbox>
                </div>
            </template>
            <template v-else>
                <a-checkbox :indeterminate="item.indeterminate" :checked="item.checkAll"
                    @change="onCheckAllChange($event, index)" style="margin-right: 10px;">
                    全部
                </a-checkbox>
            </template>
            
            <a-checkbox-group v-model="item.allChecked" @change="change($event, index)">
                <a-checkbox v-for="(child, childIdx) in item.child" :key="childIdx" :value="child.id"
                    class="mb-ten">
                    {{ child.title }}
                </a-checkbox>
            </a-checkbox-group>
        </div>
            
    </div>
</template>
<script>
export default {
    name: "checkedList",
    props: {
        data: {
            type: Array
        },
        idx:{
            type:Number || String
        }
    },
    
    methods: {
        change(checkedList, index) {
            // console.log(checkedList, index)
            let obj = {
                checkedList: checkedList,
                index: Number(index),
                idx: Number(this.idx)
            }
            this.$emit('changeChecked', obj)
        },
        onCheckAllChange(e, index) {
            let obj = {
                checkAll: e.target.checked,
                index: Number(index),
                idx: Number(this.idx)
            }
            this.$emit('onCheckAlls', obj)
        },
    }
}
</script>

<style scoped lang="less">
.search-title {
    font-weight: bold;
    margin-bottom: 10px;
}

.search-check {
    padding-left: 20px;
}

.search:last-child {
    margin-bottom: 38px;
}

/deep/ .ant-checkbox {
    .ant-checkbox-inner {
        border: 1px solid #CEDAE0;
        background-color: #ffffff;
    }
}

// 设置选中的颜色
/deep/ .ant-checkbox-checked .ant-checkbox-inner,
/deep/ .ant-checkbox-indeterminate .ant-checkbox-inner {
    background-color: #3987EB;
    border: none;
}

/deep/ .ant-checkbox-indeterminate .ant-checkbox-inner {
    background-color: #ffffff;
}

/deep/ .ant-checkbox-indeterminate .ant-checkbox-inner:after {
    background-color: #3987EB;
}
</style>